//    Copyright (C) Kherty.  All rights reserved.
using System.ComponentModel;
using System.Diagnostics.Contracts;

namespace OpenLS.Spreadsheet.UI
{
    class PasteSpecialOperation: INotifyPropertyChanged
    {
        public PasteSpecialOperation(): this(RangeFunctions.ApplyAll)
        {
        }

        public PasteSpecialOperation(RangeFunction rangeFunction)
        {
            _rangeFunction = rangeFunction;
        }

        private bool _transpose;
        public bool Transpose
        {
            get { return _transpose; }
            set { _transpose = value; }
        }

        private RangeFunction _rangeFunction;

        public RangeFunction RangeFunction
        {
            get { return _rangeFunction; }
            set { _rangeFunction = value; }
        }
	
        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        public CellsRange GetTargetRange (Range r, Worksheet worksheet)
        {
            Contract.Requires(r != null);
            Contract.Requires(worksheet != null);
            Contract.Ensures(Contract.Result<CellsRange>() != null);
            Contract.Ensures(Contract.Result<CellsRange>().Worksheet == worksheet);
            var offset = r.Address.Offset;
            if (Transpose)
                offset = new CellRelativeAddress(offset.Column, offset.Row);
            return  CellsRange.Create(worksheet, new RangeAddress(worksheet.ActiveCell.Address,
    worksheet.ActiveCell.Address + offset   ));

        }
    }
}
